Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the custom unit option of relativeTime #566

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

ktmouk
Copy link
Contributor

@ktmouk ktmouk commented Oct 15, 2023

This PR adds the relativeTime options to support custom units and updates the documentation accordingly.
Close: #565

@vercel
Copy link

vercel bot commented Oct 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-example-next-13 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 3:35pm

@vercel
Copy link

vercel bot commented Oct 15, 2023

@ktmouk is attempting to deploy a commit to the next-intl Team on Vercel.

A member of the Team first needs to authorize it.

@ktmouk ktmouk changed the title Add the custom unit option of relativeTime Add the custom unit of relativeTime Oct 15, 2023
@ktmouk ktmouk changed the title Add the custom unit of relativeTime Support custom unit of relativeTime Oct 15, 2023
@ktmouk ktmouk changed the title Support custom unit of relativeTime feat: Add the custom unit option of relativeTime Oct 15, 2023
Comment on lines 18 to 35
const UNIT_SECONDS = {
second: SECOND,
seconds: SECOND,
minute: MINUTE,
minutes: MINUTE,
hour: HOUR,
hours: HOUR,
day: DAY,
days: DAY,
week: WEEK,
weeks: WEEK,
month: MONTH,
months: MONTH,
quarter: QUARTER,
quarters: QUARTER,
year: YEAR,
years: YEAR
} as const;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added quarter and plural forms to make it match RelativeTimeFormatUnit type.

@ktmouk ktmouk marked this pull request as ready for review October 15, 2023 12:25
years: YEAR
} as const;

function resolveRelativeTimeUnit(seconds: number) {
Copy link
Contributor Author

@ktmouk ktmouk Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add quarter here because I believe we don't want to use the quarter unit in most cases.

Copy link
Owner

@amannn amannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a fantastic PR, thank you so much for this great contribution! 👏👏

I only added a minor commit from a local experiment where I wanted to check if the map you've introduced covers all relative time units.

@amannn amannn merged commit 6e1bc35 into amannn:main Oct 18, 2023
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom unit option of relativeTime
2 participants